package com.ke.jun.view.widght

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import com.ke.jun.view.utils.dp2px

class PathView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr){
    private var  centerX:Float=0F
    private var  centerY:Float=0F
    private var  radius:Float=0F
    private val paadding=dp2px(10f)
    private val paint=Paint().apply {
        color=Color.RED
        isAntiAlias=true
        strokeWidth=dp2px(10f)
        style=Paint.Style.STROKE
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        val path=Path()
//        path.addCircle(centerX,centerY,radius,Path.Direction.CW)
        val rect=RectF(radius-paadding,radius-paadding,3*radius,3*radius)
//        path.addArc(rect,0f,360f)
//        path.arcTo(rect,0f,40f)
//        path.lineTo(500f,900f)
        path.moveTo(100f,200f)
        path.rLineTo(500f,0f)
        canvas.drawPath(path,paint)

    }


    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val widthSize = MeasureSpec.getSize(widthMeasureSpec)
        val heightSize = MeasureSpec.getSize(heightMeasureSpec)
        val min=if(widthSize>heightSize)heightSize else widthSize
        centerX= (min/2).toFloat()
        centerY= (min/2).toFloat()
        radius= (min/4).toFloat()
        setMeasuredDimension(min,min)
    }

}